package py.org.atom.seam.util;

import org.jboss.seam.annotations.Name;

@Name("UString")
public class UString {

	public static final boolean isEmpty(String in){
		
		if(in == null)
			return true;
		if(in.trim().equals(""))
			return true;
		
		return false;
	}
	
	public static final boolean equal(String one, String two){
		
		if(one == null)
			return false;
		if(two == null)
			return false;
		if(one.trim().equals(two.trim()))
			return true;
		
		return false;
	}
	
	public static final String toLike(String in){
		if(isEmpty(in))
			return "%";
		return in.trim();
	}
	
	public static final String crop(String text, int len){
		if(text == null)
			return null;
		if(len <= 4)
			return text.trim();
		if(text.trim().length() <= len)
			return text.trim();
		len = len - 4;
		return text.trim().substring(0, len);
	}
	
	public static final boolean hasChar(String text, String charString){
		
		for(int i=0;i<charString.length();i++){
			char c = (charString.substring(i,(i+1))).charAt(0);
			if(text.indexOf(c) > 0){
				return true;
			}
		}
		
		return false;
	}
	
}
